/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package org.sbbs.demo.entity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.sql.Time;
import java.sql.Timestamp;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.CurrentTimestamp;
import static org.hibernate.generator.EventType.INSERT;
import static org.hibernate.generator.EventType.UPDATE;
import org.sbbs.base.jpa.entity.BaseEntity;

/**
 *
 * @author jenkins
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "time_base_entity")
@Comment("样例表")
public class TimeBaseBean extends BaseEntity {

    @Column(nullable = true)
//    @JdbcTypeCode(INTERVAL_SECOND)
    private Duration duration;
//     mapped as TIMESTAMP
    @Column(nullable = true)
//    @Temporal(TemporalType.TIMESTAMP)
    private Instant instant;
    // mapped as DATE
    private LocalDate localDate;
    // mapped as TIMESTAMP
    private LocalDateTime localDateTime;
// mapped as TIME
    @Comment("LocalTime包装")
    @Column(name = "local_time", nullable = true)
    private LocalTime localTime;
// mapped as TIMESTAMP or TIMESTAMP_WITH_TIMEZONE
    @Column(nullable = true)
    private OffsetDateTime offsetDateTime;
// mapped as TIME or TIME_WITH_TIMEZONE
    @Column(nullable = true)
    private OffsetTime offsetTime;

    // mapped as VARCHAR
    @Column(nullable = true)
    private TimeZone timeZone;

// mapped as TIMESTAMP or TIMESTAMP_WITH_TIMEZONE
    @Column(nullable = true)
    private ZonedDateTime zonedDateTime;

// mapped as VARCHAR
    @Column(nullable = true)
    private ZoneOffset zoneOffset;

    @Column(nullable = true)
    private Calendar calendar;

    @Column(nullable = true)
    private Date dateField;
    @Column(nullable = true)
    private Time timeField;
    @Column(nullable = true)
    private Timestamp timestampField;

    @CurrentTimestamp(event = INSERT)
    public Instant createdAt;

    @CurrentTimestamp(event = {INSERT, UPDATE})
    public Instant lastUpdatedAt;
}
